<!--
 * @Author: your name
 * @Date: 2022-04-09 15:55:55
 * @LastEditTime: 2022-04-09 16:14:08
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\获取一个0-50的不重复数组.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    //获取1-50不重复随机数组 改变数组长度
    var number = 50
    var arr=[]
    for(var i=1;i<number;i++) {
      arr.push(i);
    }
    var result=[];
    for(var j=number-1;j>=0;j--) {
      var rand=Math.ceil(Math.random()*j)
      console.log(rand,"rand")
      result.push(arr.splice(rand,1));
    }
    console.log(result,"result")
  </script>
</body>
</html>